package xin.marcher.module.common.enums.inventory;

import com.google.common.collect.Maps;

import java.util.Map;

/**
 * 库存 操作类型枚举
 */
public enum InventoryDeductionTypeEnum {

    /**
     * 扣减库存
     */
    INVENTORY_DETAIL_DEDUCTIONS_TYPE(10, "库存扣减"),
    /**
     * 库存退货
     */
    INVENTORY_DETAIL_REFUND_TYPE(20, "库存退货"),
    ;


    private Integer code;

    private String value;

    InventoryDeductionTypeEnum(Integer code, String value) {
        this.code = code;
        this.value = value;
    }

    public Integer getCode() {
        return code;
    }

    public String getValue() {
        return value;
    }

    public static Map<Integer, String> toMap() {
        Map<Integer, String> map = Maps.newHashMap();
        for (InventoryDeductionTypeEnum element : InventoryDeductionTypeEnum.values()) {
            map.put(element.getCode(), element.getValue());
        }
        return map;
    }

    public static InventoryDeductionTypeEnum getByCode(Integer code) {
        if (code == null) {
            return null;
        }
        for (InventoryDeductionTypeEnum element : InventoryDeductionTypeEnum.values()) {
            if (code.equals(element.getCode())) {
                return element;
            }
        }
        return null;
    }


}
